package edu.ujf.sharepas.rcp;

import java.rmi.RemoteException;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionConstants;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonMenuConstants;
import org.eclipse.ui.navigator.ICommonViewerSite;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;

import edu.ujf.sharepas.navigator.OpenPropertyAction;
import edu.ujf.sharepas.rcp.actions.AddFileAction;

public class LibraryActionProvider extends CommonActionProvider {

	private AddFileAction addFileAction ;
	
	public LibraryActionProvider() {
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
	 */
	public void init(ICommonActionExtensionSite aSite) {
	
		ICommonViewerSite viewSite = aSite.getViewSite();
		if(viewSite instanceof ICommonViewerWorkbenchSite) {
			ICommonViewerWorkbenchSite workbenchSite = 
				(ICommonViewerWorkbenchSite) viewSite;
			try {
				addFileAction = new AddFileAction(workbenchSite.getSelectionProvider(),Application.c.getUser(),"Ajouter un Fichier");
			} catch (RemoteException e) {
				e.printStackTrace();
			}
		}
	}	

	/* (non-Javadoc)
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
	 */
	public void fillActionBars(IActionBars actionBars) { 
		/* Set up the property open action when enabled. */
		if(addFileAction.isEnabled())
			actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, addFileAction);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
	 */
	public void fillContextMenu(IMenuManager menu) {
		if(addFileAction.isEnabled())
			menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, addFileAction);		
	}

}
